package com.ccs.functions;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class Login {

	public void app(WebDriver driver) throws Exception {
		
		String url = "http://ehealthcorp-qa.stluke.com.ph/login";
		driver.get(url);
		System.out.println(driver.getTitle());
		WebElement username = driver.findElement(By.xpath("//input[@id='j_username']"));
		WebElement password = driver.findElement(By.xpath("//input[@id='j_password']"));
		WebElement button = driver.findElement(By.xpath("//a[contains(., 'LOG IN')]"));
		
		//login to web app page
		username.sendKeys("jude_bordallo@yahoo.com");
		password.sendKeys("password");
		button.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		try{
			driver.findElement(By.xpath("//a[contains(.,'Logout')]"));
			System.out.println("Login successful in WebApp!");
		}catch(Exception e){
			System.out.println("Login failed in WebApp.");
		}
	}
	
	public void hcs(WebDriver driver, String user) throws Exception {
		
		String hcs = "http://hcs-qa:2112";			//HCS - Global City
		//String hcs = "http://192.168.105.2:8084";		//HCS - Quezon City
		driver.get(hcs);
		System.out.println(driver.getTitle());
		
		WebElement username = driver.findElement(By.xpath("//input[@id='username']"));
		WebElement password = driver.findElement(By.xpath("//input[@id='password']"));
		WebElement button = driver.findElement(By.xpath("//input[@class='btnLogin']"));
		
		//login to hcs
		if(user.equals("pharmacy")){
			username.sendKeys("pharmacy1");
		}else if(user.equals("nursing")){
			username.sendKeys("10thnw");
		}else if(user.equals("billing")){
			username.sendKeys("pba1");
		}else if(user.equals("specialunit")){
			username.sendKeys("or1");
		}else if(user.equals("dasoss")){
			username.sendKeys("dastech8");
		}else if(user.equals("admission")){
			username.sendKeys("adm1");
		}
		password.sendKeys("123qweuser");
		button.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		try{
			driver.findElement(By.xpath("//a[contains(.,'Logout')]"));
			System.out.println(user +" Login successful!");
		}catch(Exception e){
			System.out.println(user +" Login failed.");
		}
		
	}
	
	public void admin(WebDriver driver) throws Exception {
		
		String url = "http://192.168.137.39:9091/login.html";
		driver.get(url);
		System.out.println(driver.getTitle());
		WebElement username = driver.findElement(By.xpath("//input[@id='j_username']"));
		WebElement password = driver.findElement(By.xpath("//input[@id='j_password']"));
		WebElement button = driver.findElement(By.xpath("//input[@value='LOGIN']"));
		
		//login to web app page
		username.sendKeys("dang");
		password.sendKeys("Daphn3!");
		button.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		try{
			driver.findElement(By.xpath("//a[contains(.,'Logout')]"));
			System.out.println("Login successful in Admin!");
		}catch(Exception e){
			System.out.println("Login failed in Admin.");
		}
		
	}
	
	
}
